package com.cares.sh.controller;

import com.cares.sh.model.User;
import com.cares.sh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {


    @RequestMapping("/list")
    public List<User> list(){
        return userService.list();
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Long add(User user){
        return userService.insert(user);
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public User selectById(@PathVariable("id") Long id){
        return userService.selectById(id);
    }


    private UserService userService;


    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
}
